from django.db import models

class BaseModel(models.Model):
  id = models.AutoField(primary_key=True)
  date_created = models.DateTimeField(auto_now_add=True)
  date_modified = models.DateTimeField(auto_now=True)
  active = models.BooleanField()
  version = models.IntegerField()
  
  class Meta:
    abstract=True

class Language(BaseModel):
  code = models.CharField(max_length=5)
  description = models.CharField(max_length=50)

  class Meta:
    db_table = 'tbl_language'
  
class CharTranslatableItem(BaseModel):
  language = models.ForeignKey(Language)
  group = models.CharField(max_length=50, db_index=True)
  key = models.CharField(max_length=50, db_index=True)
  value = models.CharField(max_length=150)

  class Meta:
    db_table = 'tbl_char_translatable_item'
    unique_together = ('group','key')
  
class TextTranslatableItem(BaseModel):
  language = models.ForeignKey(Language)
  group = models.CharField(max_length=50, db_index=True)
  key = models.CharField(max_length=50, db_index=True)
  value = models.TextField(max_length=500)
  
  class Meta:
    db_table = 'tbl_text_translatable_item'
    unique_together = ('group','key')
  
  
class Country(BaseModel):
  key = models.CharField(max_length=50, db_index=True)
  default_text = models.CharField(max_length=100, db_index=True)
  translated_text = ''
  
  class Meta:
    db_table = 'tbl_countries'
    
    
class State(BaseModel):
  country = models.ForeignKey(Country)
  key = models.CharField(max_length=50, db_index=True)
  default_text = models.CharField(max_length=100, db_index=True)
  translated_text = ''
  
  class Meta:
    db_table = 'tbl_states'
    
class Address(BaseModel):
  country = models.ForeignKey(Country)
  state = models.ForeignKey(State)
  street = models.CharField(max_length=50)
  number = models.CharField(max_length=20)
  is_house = models.BooleanField(default=False)
  floor = models.CharField(max_length=5)
  apartment = models.CharField(max_length=5)
  zip_code = models.CharField(max_length=20)
  
  class Meta:
    db_table = 'tbl_addresses'

class Currency(BaseModel):
  symbol = models.CharField(max_length=10)
  default_text = models.CharField(max_length=50)
  translated_text = ''
  
  class Meta:
    db_table = 'tbl_currencies'
  